package cn.com.constant;

import java.util.regex.Pattern;

/**
 * 配置一些常量
 *
 * @author WZQ
 * @date 2021-08-28 11:52
 **/
public class ConfigConstant {

    /**
     * 不区分大小写，将所有内容作为一行进行匹配，.会匹配换行符，注意：\s可以匹配任何空白字符，包括换行符
     */
    public static final int DEFAULT_PATTERN_FLAGS = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;

    //---------------------------------启动参数---------------------------------

    public static final String PIPELINE_NAME = "applicationName";
    public static final String EXECUTION_MODE = "executionMode";
    public static final String STREAMING_MODE = "streaming";
    public static final String BATCH_MODE = "batch";
    public static final Pattern EXECUTION_MODE_PATTERN = Pattern.compile("streaming|batch", DEFAULT_PATTERN_FLAGS);
    public static final String SQL_FILE_PATH = "sqlFilePath";

    //---------------------------------SQL类型判断正则表达式---------------------------------
    /**
     * SET ('key' = 'value')?<br>
     * 示例：SET 'table.planner' = 'blink'
     */
    public static final Pattern SET_PATTERN = Pattern.compile("SET\\s+'([A-Za-z].+)'\\s*=\\s*'(.+)\\s*'", DEFAULT_PATTERN_FLAGS);
    /**
     * CREATE CATALOG catalog_name WITH (key1=val1, key2=val2, ...)<br>
     * 示例：create catalog hive_catalog with('name' = 'my_hive', 'conf' = '/home/hive/conf')
     */
    public static final Pattern CREATE_HIVE_CATALOG_PATTERN = Pattern.compile("CREATE\\s+CATALOG\\s+HIVE_CATALOG\\s+WITH\\s*\\((\\s*'[A-Za-z].+'\\s*=\\s*'.+'\\s*,*\\s*)+\\)\\s*", DEFAULT_PATTERN_FLAGS);
    /**
     * CREATE [TEMPORARY|TEMPORARY SYSTEM] FUNCTION [IF NOT EXISTS] [catalog_name.][db_name.]function_name AS identifier [LANGUAGE JAVA|SCALA|PYTHON]<br>
     * 示例：create function test_fun as com.flink.testFun
     */
    public static final Pattern CREATE_FUNCTION_PATTERN = Pattern.compile("CREATE\\s+FUNCTION\\s+([A-Za-z]\\w+)\\s+AS\\s+([A-Za-z].+)\\s*", DEFAULT_PATTERN_FLAGS);
    /**
     * INSERT INTO [catalog_name.][db_name.]table_name [column_list] select_statement<br>
     * INSERT OVERWRITE [catalog_name.][db_name.]table_name [PARTITION part_spec] [column_list] select_statement<br>
     * 插入和覆盖语句<br>
     * 示例：insert into a_table select * from b_table<br>
     * 示例：insert overwrite a_table partition (dt = 20210828) select * from b_table
     */
    public static final Pattern INSERT_PATTERN = Pattern.compile("INSERT\\s+.*", DEFAULT_PATTERN_FLAGS);
    /**
     * SELECT <br>
     * 查询语句<br>
     * 示例：select * from db.table1
     */
    public static final Pattern SELECT_PATTERN = Pattern.compile("SELECT\\s+.*", DEFAULT_PATTERN_FLAGS);


    //---------------------------------select结果展示相关---------------------------------

    public static final int COLUMN_CHARACTER_MAX_COUNT = 30;


    //---------------------------------SQL方言转换---------------------------------

    public static final String SQL_DIALECT = "table.sql-dialect";
    public static final String HIVE_DIALECT = "hive";


    //--------------------------------------------创建catalog-------------------------------------------------------

    public static final String CATALOG_NAME = "name";
    public static final String CATALOG_HIVE_CONF = "conf";
    public static final String CATALOG_HIVE_VERSION = "version";
    /**
     * flink建表之后表schema信息存放位置
     */
    public static final String DEFAULT_HIVE_DATABASE = "default";


    //--------------------------------------------checkpoint配置-------------------------------------------------------


    /**
     * 是否对流式任务开启checkpoint，默认开启
     */
    public static final String CHECKPOINT_ENABLE = "checkpointEnable";
    /**
     * 是否开启rocksdb状态后端，默认不开启
     */
    public static final String CHECKPOINT_ROCKSDB_ENABLE = "checkpointRocksDBEnable";
    /**
     * checkpoint地址
     */
    public static final String CHECKPOINT_DIR_NAME = "checkpointDir";
    /**
     * checkpoint间隔，默认60秒，单位：秒
     */
    public static final String CHECKPOINT_INTERVAL_NAME = "checkpointInterval";
    /**
     * checkpoint间隔默认值，60秒
     */
    public static long CHECKPOINT_INTERVAL = 60L;
    /**
     * checkpoint超时时间，默认5分钟，单位：秒
     */
    public static final String CHECKPOINT_TIMEOUT_NAME = "checkpointTimeout";
    /**
     * checkpoint超时时间默认值，5分钟
     */
    public static long CHECKPOINT_TIMEOUT = 300L;
    /**
     * 两次checkpoint快照最短间隔，1秒
     */
    public static long CHECKPOINT_MIN_PAUSE_BETWEEN_CHECKPOINTS = 1000L;

}
